package com.mashibing.juc.c_028_FalseSharing;

public class T02_CacheLinePadding {

    private static class Padding {
        public volatile long p1, p2, p3, p4, p5, p6, p7, p8;
        public volatile long p9, p10, p11, p12, p13, p14, p15, p16;
    }

    private static class T extends Padding {
        public volatile long x = 0L;
    }

    public static Padding[] arr = new Padding[2];

    static {
        arr[0] = new Padding();
        arr[1] = new Padding();
    }

    public static void main(String[] args) throws Exception {

        Thread t1 = new Thread(()->{
            for (long i = 0; i < 1000_0000L; i++) {
                arr[0].p1 = i;
            }
        });

        Thread t2 = new Thread(()->{
            for (long i = 0; i < 1000_0000L; i++) {
                arr[1].p9 = i;
            }
        });

        final long start = System.nanoTime();
        t1.start();
        t2.start();
        t1.join();
        t2.join();
        System.out.println((System.nanoTime() - start)/100_0000);
    }

}
